package com.tarena.lbs.business.servcie.impl;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.business.dao.mapper.BusinessCategoryMapper;
import com.tarena.lbs.business.pojo.po.BusinessCategoryPO;
import com.tarena.lbs.business.pojo.vo.BusinessCategoryVO;
import com.tarena.lbs.business.servcie.BusinessCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class BusinessCategoryServiceImpl implements BusinessCategoryService {
    @Autowired
    private BusinessCategoryMapper businessCategoryMapper;

    @Override
    public List<BusinessCategoryVO> allCategories() {
        log.info("查询所有分类");
        List<BusinessCategoryPO> poList = businessCategoryMapper.selectList(null);
        List<BusinessCategoryVO> voList = poList.stream()
                .map(po -> {
            BusinessCategoryVO vo = new BusinessCategoryVO();
            BeanUtils.copyProperties(po, vo);

            return vo;
        }).collect(Collectors.toList());

        return voList;
    }
}
